package cn.iocoder.yudao.module.erp.controller.admin.finance;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.erp.controller.admin.finance.vo.category.PRCategorySaveVO;
import cn.iocoder.yudao.module.erp.controller.admin.finance.vo.category.PRCategoryVO;
import cn.iocoder.yudao.module.erp.service.finance.ErpFinancePaymentCategoryService;
import cn.iocoder.yudao.module.erp.service.finance.ErpFinanceReceiptCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - ERP 收支类别")
@RestController
@RequestMapping("/erp/finance-pr-category")
@Validated
public class ErpFinancePRCategoryController {
    @Resource
    private ErpFinancePaymentCategoryService erpFinancePaymentCategoryService;
    @Resource
    private ErpFinanceReceiptCategoryService erpFinanceReceiptCategoryService;

    @PostMapping("/create")
    @Operation(summary = "创建收支类别")
    public CommonResult<Boolean> createFinancePayment(@Valid @RequestBody PRCategorySaveVO prCategorySaveVO) {
        if(prCategorySaveVO.getPr().equals("payment")){
            erpFinancePaymentCategoryService.createFinancePaymentCategory(prCategorySaveVO);
            return success(true);
        }
        if(prCategorySaveVO.getPr().equals("receipt")){
            erpFinanceReceiptCategoryService.createFinanceReceiptCategory(prCategorySaveVO);
            return success(true);
        }
        return error(422,"pr值应该为payment或receipt");
    }

    @GetMapping("/get")
    @Operation(summary = "获取收支类别")
    public CommonResult<List<PRCategoryVO>> getFinancePayment(@Valid @RequestParam String pr) {
        if(pr.equals("payment")){
            return success(erpFinancePaymentCategoryService.getFinancePaymentCategories());
        }
        if(pr.equals("receipt")){
            return success(erpFinanceReceiptCategoryService.getFinanceReceiptCategories());
        }
        return error(422,"pr值应该为payment或receipt");
    }
}
